#include "../libnl/nl_client.h"

#pragma comment(lib, "ws2_32.lib")

int my_nl_on_packet_recv(void *nlc, char *buf, size_t len)
{
    printf("*****%d****\n", len);
    ((nl_conn *)nlc)->send_packet("kekeke", 6);
    return 0;
}

int my_nl_on_connect(void *nlc)
{
    ((nl_conn *)nlc)->send_packet("kekeke", 6);
    printf("*****my_nl_on_connect****\n");
    return 0;
}

int my_nl_on_close(void *nlc)
{
    printf("*****my_nl_on_close****\n");
    return 0;
}

typedef int evutil_socket_t;

int main()
{
    evutil_socket_t conn_fd, conn_fd2;
	struct sockaddr_in conn_addr;

#ifdef WIN32
    WSADATA wsaData;
    
    int err = WSAStartup( MAKEWORD( 2, 0 ), &wsaData );
    if ( err != 0 ) {
        printf( "Couldn't find a useable winsock.dll.\n" );
        return -1;
    }
#endif

    get_nl_client().init();
    get_nl_client().register_on_packet_recv(my_nl_on_packet_recv);
    get_nl_client().register_on_connect(my_nl_on_connect);
    get_nl_client().register_on_close(my_nl_on_close);

    conn_fd2 = socket(AF_INET, SOCK_STREAM, 0);
    if (conn_fd2 < 0)
    {
        printf("socket failed\n");
    }

    conn_fd = socket(AF_INET, SOCK_STREAM, 0);
    if (conn_fd < 0)
    {
        printf("socket failed\n");
    }

    /* connect to google.com */
    memset(&conn_addr, 0, sizeof(conn_addr));
    conn_addr.sin_family = AF_INET;
    conn_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    conn_addr.sin_port = htons(5555);

    get_nl_client().nl_connect(conn_fd, &conn_addr);
    get_nl_client().nl_connect(conn_fd2, &conn_addr);
    get_nl_client().start();
    get_nl_client().stop();

#ifdef WIN32
    WSACleanup();
#endif
    return 0;
}